/*
 * Copyright 2014 Semidata. All rights reserved.
 */
package com.semidata.rtd.engine.executor;

import com.semidata.rtd.engine.job.Task;

/**
 * @author shewei@semidata.com, She Wei
 * 
 */
public class TaskWrapper {

	public enum Status {
		NOT_START, RUNNING, DONE,
	};

	private Task task;
	private Status status;
	private long expireTime;

	public TaskWrapper(Task task) {
		this.task = task;
		this.status = Status.NOT_START;
		this.expireTime = task.getTimeout() == 0 ? Long.MAX_VALUE : (System.currentTimeMillis() + task.getTimeout());
	}

	public void beforeExecution() {
		task.beforeExecution();
	}
	
	public void run() throws Exception {
		status = Status.RUNNING;
		task.beforeExecution();
		task.run();
	}
	
	public void done(Exception exception) {
		status = Status.DONE;
		task.afterExecution(exception);
	}
	
	public Status getStatus() {
		return status;
	}
	
	public long getExpireTime() {
		return expireTime;
	}

	//debug
//	public String getTaskClass() {
//		return task.getClass().getName();
//	}
}
